package pzl.com.drawrelated.views;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.text.TextPaint;
import android.util.AttributeSet;
import android.view.View;

/**
 * @author zl.peng
 * @version [1.0, 2016-11-17]
 */
public class V2 extends View {
    public V2(Context context) {
        super(context);
    }

    public V2(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public V2(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        Paint p = new Paint();
        TextPaint tp = new TextPaint();

        p.setAntiAlias(true);
        p.setStyle(Paint.Style.STROKE);
        p.setColor(Color.BLUE);
        p.setStrokeWidth(6);

        Path ph = new Path();
        ph.moveTo(50, 50);
        ph.lineTo(200, 70);
        ph.lineTo(400, 100);
        ph.lineTo(600, 170);
        ph.lineTo(740, 400);
        // ph.close();

        canvas.drawPath(ph, p);

        canvas.save();
        canvas.clipPath(ph);
        canvas.drawColor(Color.RED);
        canvas.restore();


        tp.setTextSize(22);
        canvas.drawText("ABC", 60, 80, tp);
        canvas.drawText("DEF", 500, 20, tp);


    }
}
